<?php

/**
 * This is the model class for table "{{apps}}".
 *
 * The followings are the available columns in table '{{apps}}':
 * @property integer $aid
 * @property integer $uid
 * @property string $appName
 * @property string $appKeywords
 * @property string $appDescription
 * @property integer $appTemplate
 * @property integer $appType
 * @property string $joindate
 *
 * The followings are the available model relations:
 * @property User $u
 * @property Templates $appTemplate0
 * @property Apptype $appType0
 * @property Channel[] $channels
 * @property Stocks[] $stocks
 */
class Apps extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Apps the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{apps}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('uid, appTemplate, appType', 'numerical', 'integerOnly'=>true),
			array('appName, appKeywords, appDescription, joindate', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('aid, uid, appName, appKeywords, appDescription, appTemplate, appType, joindate', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'u' => array(self::BELONGS_TO, 'User', 'uid'),
			'appTemplate0' => array(self::BELONGS_TO, 'Templates', 'appTemplate'),
			'appType0' => array(self::BELONGS_TO, 'Apptype', 'appType'),
			'channels' => array(self::HAS_MANY, 'Channel', 'aid'),
			'stocks' => array(self::HAS_MANY, 'Stocks', 'aid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'aid' => 'Aid',
			'uid' => 'Uid',
			'appName' => 'App Name',
			'appKeywords' => 'App Keywords',
			'appDescription' => 'App Description',
			'appTemplate' => 'App Template',
			'appType' => 'App Type',
			'joindate' => 'Joindate',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('aid',$this->aid);
		$criteria->compare('uid',$this->uid);
		$criteria->compare('appName',$this->appName,true);
		$criteria->compare('appKeywords',$this->appKeywords,true);
		$criteria->compare('appDescription',$this->appDescription,true);
		$criteria->compare('appTemplate',$this->appTemplate);
		$criteria->compare('appType',$this->appType);
		$criteria->compare('joindate',$this->joindate,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}